﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StockAna
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();
            DialogResult rst = fd.ShowDialog();
            if (rst == System.Windows.Forms.DialogResult.OK)
            {
                StockPrize.LoadFile(fd.FileName);
            }
        }

        private async void button4_Click(object sender, EventArgs e)
        {
            int zeroCnt = await StockPrize.UpdateAll((int c, int a) =>
            {
                label1.Text = string.Format("{0}/{1}", c, a);
                label1.Refresh();
            });

            label1.Text = string.Format("zero:{0}", zeroCnt);
            StockSafe[] all = StockSafe.All();
            foreach (StockSafe ss in all)
            {
                ss.Save();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Visible = true;
            textBox1.Focus();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                StockSafe ss = StockSafe.Find(textBox1.Text);
                textBox1.Visible = false;
                textBox1.Text = "";
                SafeEditForm edit = new SafeEditForm(ss);
                edit.Show();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ListForm f = new ListForm();
            f.Setup(StockSafe.Top(100));
            f.Show();
        }
    }
}
